import sys
import os
import django

DJANGO_PRO_DIR = r"E:\pycharm_projects\douban_crawler\movie\movie"
sys.path.append(DJANGO_PRO_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
django.setup()


def setup_django_model(project_path=DJANGO_PRO_DIR):
    sys.path.append(project_path)
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
    django.setup()

# # 必须要在 初始化djnago 之后导入 models
# from users.models import User
#
# user = User()
# user.name = "zhangsan"
# user.age = 18
# user.sex = "male"
# user.save()


if __name__ == "__main__":
    setup_django_model()
    from apis_1_0.models import Movie
    movie = Movie()
    # ret = Movie.objects.get(publish_year=2020)
    # print(ret.movie_name)
    movie.movie_name = "《星际穿越》"
    movie.publish_year = 2019
    movie.save()
